
<style type="text/css">
	select{
		width:60px;
	}
	.p{
		
		width:85%;
		/*border:1px solid red;*/
		margin:0 auto;
		margin-top:50px; 
	}
	#content{
		text-align: left;
	}
	button{
		float: right;
	}
	.font{
		 font-family: "Roboto", sans-serif;
   		 font-size: 1rem;
    	 font-weight: normal;
         line-height: 1.5;
         color: #707070;
	}
	
</style>


		<div class='font' style="background-color:#fff;height:520px;">
			
			<div class='p' style='padding-top:20px;'>
					<h3>定时策略</h3>
			</</p>
			<div id="app" style=''>
				<p class='p' >
					<span>订单待确认状态，在到达入住当天</span>
					&nbsp
					<select id='se0'>
						<option>12</option>
						<option>13</option>
						<option>14</option>
						<option>15</option>
						<option>16</option>
						<option>17</option>
						<option>18</option>
						<option>19</option>
						<option>20</option>
						<option>21</option>
					</select>
					&nbsp
					<span>时订单未确认则变更为“已取消”订单状态</span>
					<button class='btn' id='btn0'>关闭</button>
				</p>
				<p class='p'>
					<span>订单已确认状态，在到达离店当天</span>
					&nbsp
					<select id='se1'>
						<option>10</option>
						<option>11</option>
						<option>12</option>
						<option>13</option>
						<option>14</option>
						<option>15</option>
						<option>16</option>
						<option>17</option>
						<option>18</option>
					</select>
					&nbsp
					<span>时自动变更为“已结束”订单状态</span>
					<button class='btn' id='btn1'>关闭</button>
				</p>
				<p class='p'>
					<span>酒店每日运营数据于第二日</span>
					&nbsp
					<select id='se2'>
						<option>8</option>
						<option>9</option>
						<option>10</option>
						<option>11</option>
						<option>12</option>
						<option>13</option>
						<option>14</option>
						<option>15</option>
						<option>16</option>
						<option>17</option>
						<option>18</option>
					</select>
					&nbsp
					<span>时发送至酒店“数据通知”相应权限人员</span>
					<button class='btn' id='btn2'>关闭</button>
				</p>
				<p class='p'>
					<span>订单待确认状态，</span>
					&nbsp
					<select id='se3'>
						<option>6</option>
						<option>7</option>
						<option>8</option>
						<option>9</option>
						<option>10</option>
						<option>11</option>
						<option>12</option>
					</select>
					&nbsp
					<span>小时之内未确认则自动变更为“已取消”订单状态</span>
					<button class='btn' id='btn3'>关闭</button>
				</p>
				<p class='p'>
						<span>订单待支付状态，未进行支付，在</span>
						&nbsp
						<select selected="30" id='se4' readonly>
							<option>30</option>
							<!-- <option>45</option> -->
						</select>
						&nbsp
						<span>分钟后自动取消订单</span>
						<button class='btn' id='btn4'>关闭</button>
				</p>
				<div style='clear:both;'></div>
				<div class='p'><div style='text-align:center!important;border:none;width:141px;height:41px;line-height:41px;margin:0 auto;background:#32c787;color:#fff;' onclick="submit()">提交</div></div>
			
				
			</div>
		</div>

<script type="text/javascript">
var hotel_id=0;

	// 获取数据
	var json=[
			{value:"",status:1},
			{value:"",status:0},
			{value:"",status:0},
			{value:"",status:1},
			{value:"",status:0}
	]
	$.ajax({
        url : 'crontab/list',
        type : "get",
        dataType : "json",
        data : '',
        cache : false,
        async : false,
        success : function(data) {
        		/* 获取的参数 */
			hotel_id=data.rows[0].hotel_id;
			console.log(data.rows[0])
			json[0].value=data.rows[0].value1
			json[1].value=data.rows[0].value2
			json[2].value=data.rows[0].value3
			json[3].value=data.rows[0].value4
			json[4].value=data.rows[0].value5
			json[0].status=data.rows[0].status1
			json[1].status=data.rows[0].status2
			json[2].status=data.rows[0].status3
			json[3].status=data.rows[0].status4
			json[4].status=data.rows[0].status5
        },
        error : function(error) {
           console.log("接口请求失败"+error)
        }
    });
	console.log(json)
	// 赋值
	for(var i=0;i<json.length;i++){
			$("#se"+i).find("option:selected").text(json[i].value)
			if(json[i].status==1){//开启
				$("#btn"+i).html("关闭")
			}else{
				$("#btn"+i).html("开启")
			}
	}
	// 状态按钮绑定函数
	function clickChange(){
		$(".btn").each(function(i){
			 $(this).click(function(){
			 	if($(this).html()=='关闭'){
			 		$(this).html("开启")
			 	}else{
			 		$(this).html("关闭")
			 	}
			 })
		})
	}
	clickChange()
	var sub=[{
		value1:'',
		value2:'',
		value3:'',
		value4:'',
		value5:'',
		status1:"",
		status2:"",
		status3:"",
		status4:"",
		status5:"",
	}];
	//组织提交数据
	var submitData=[];
	function submit(){
		submitData=[];
		for(var k=0;k<5;k++){
				submitData.push({
					"value":$("#se"+k).find("option:selected").text(),
					"status":$("#btn"+k).text()
				})
			if(submitData[k].status=="关闭"){
					submitData[k].status='1'
			}else{
					submitData[k].status='0'
			}
				
		}
		
		sub[0].value1=submitData[0].value
		sub[0].value2=submitData[1].value
		sub[0].value3=submitData[2].value
		sub[0].value4=submitData[3].value
		sub[0].value5=submitData[4].value
			
		sub[0].status1=submitData[0].status
		sub[0].status2=submitData[1].status
		sub[0].status3=submitData[2].status
		sub[0].status4=submitData[3].status
		sub[0].status5=submitData[4].status
		sub[0].hotelId=hotel_id;
		console.log(sub)
		$.ajax({
	        url : 'crontab/update',
	        type : "post",
	        dataType : "json",
	        data : sub[0],
	        cache : false,
	        async : false,
	        success : function(data) {
	        console.log("提交成功")
	        	alert("修改成功");
	        },
	        error : function(error) {
	           console.log("接口提交失败"+error)
	        }
	    });
	
		
	}

</script>
